package servlet.manage.nav;

import model.NavModel;
import net.sf.json.JSONArray;
import service.INavService;
import service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/NavUpdate")
public class NavUpdateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");//请求编码格式为utf-8
//        resp.setCharacterEncoding("UTF-8");//响应编码格式为utf-8
//        resp.setContentType("text/json;charset=utf-8");//解决传值乱码

        String ids =req.getParameter("id");
        String href =req.getParameter("href");
        String title =req.getParameter("title");
        String sta =req.getParameter("status");
        Integer id = ids == null?0:Integer.parseInt(ids);
        Integer status=sta==null?0:Integer.parseInt(sta);


        NavModel model=new NavModel();
        model.setId(id);
        model.setHref(href);
        model.setTitle(title);
        model.setStatus(status);

        INavService service =new NavServiceImpl();
        int num =service.update(model);

        JSONArray jsonArray =JSONArray.fromObject(num);
        resp.getWriter().println(jsonArray);

    }
}
